import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_shop/components/shop_search.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
   // 1. 定义字典存储接口数据
  Map resData = {};

  @override
  void initState() {
    // 3. 生命中周期调用
    getResData();
    super.initState();
  }

  // 2. 获取接口数据
  void getResData() async {
    Dio dio = Dio();
    Response res = await dio
        .get('http://smart-shop.itheima.net/index.php?s=/api/page/detail');
    setState(() {
      resData = res.data['data']['pageData'];
    });
  }

  @override
  Widget build(BuildContext context) {
     return Scaffold(   // 骨架
      body: ListView(      // 滚动容器
        children: const [
          ShopSearchBar(), // 搜索框组件
          Text('首页'),
        ],
      ),
    );
  }
}